﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Tanks
{
    class PlayerTank : Tanks
    {
        private MouseState MouseState = new MouseState();
        public override void Load(Microsoft.Xna.Framework.Content.ContentManager Content)
        {
            base.Load(Content);
        }
        public override void Update(Microsoft.Xna.Framework.GameTime time)
        {
            MouseState = Mouse.GetState();

            Cam.Camera.Location = Location ;


            //the keys for body rotation
            if (Keyboard.Keyboard.LeftKey() == true)
            {
                BodyRoation += 0.05f;
            }
            else if (Keyboard.Keyboard.RightKey() == true)
            {
                BodyRoation -= 0.05f;
            }

            //allows the tank to move back and forth  
            if (Keyboard.Keyboard.UpKey() == true)
            {
                Location += new Vector2((float)Math.Cos(((Double)BodyRoation)), (float)Math.Sin(((Double)BodyRoation)));
            }
            else if (Keyboard.Keyboard.DownKey() == true)
            {
                Location -= new Vector2((float)Math.Cos(((Double)BodyRoation)), (float)Math.Sin(((Double)BodyRoation)));

            }
            //rotates the turret head
            float Distance = Vector2.Distance(((new Vector2(MouseState.X, MouseState.Y) + Location) - (Location + Globals.Globals.CameraOffset)), Vector2.Zero);
            float yDist = (MouseState.Y + Location.Y) - (Location.Y + Globals.Globals.CameraOffset.Y);
            TurretRotation = (float)Math.Acos((double)(MouseState.X + Location.X - (Location.X + Globals.Globals.CameraOffset.X)) / (Distance));
            if (yDist < 0)
            {
                TurretRotation *= -1.0f;
            }
            
            base.Update(time);
        }
        
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch Sprties)
        {
            base.Draw(Sprties);
        }

    }
}
